//
//  YMInsertInstrumentVC.m
//  YMMedical
//
//  Created by y s on 2023/7/24.
//

#import "YMInsertInstrumentVC.h"
#import "FLAnimatedImageView.h"
#import "FLAnimatedImage.h"
#import "YMCheckCameraStatusVC.h"

@interface YMInsertInstrumentVC ()

@property (nonatomic, strong) UIScrollView *svMain;
@property (nonatomic, strong) UIView *vBg;

@property (nonatomic, strong) UILabel *lblTips;
@property (nonatomic, strong) FLAnimatedImageView *imgvIcon;

@property (nonatomic, strong) UIButton *btnFinish;

@end

@implementation YMInsertInstrumentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}

- (void)setUI{
    [self showNavTitle:KLanguage(@"insert_device_txt")];
    [SNavUtil rightIcon:self icon:@"tools_nav_home_icon" onClick:^{
        [YMBridging goHomeTabWithAlert];
    }];
    [self.view addSubview:self.svMain];
    [self.svMain addSubview:self.vBg];
    [self.vBg addSubview:self.lblTips];
    [self.vBg addSubview:self.imgvIcon];
    
    [self.view addSubview:self.btnFinish];
    
    [self.svMain mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo(0);
    }];
    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.equalTo(self.svMain);
        make.bottom.mas_equalTo(0);
    }];
    [self.lblTips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo([SFitUtil fit:15]);
    }];
    [self.imgvIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lblTips.mas_bottom).offset([SFitUtil fit:16]);
        make.bottom.mas_equalTo([SFitUtil fit:-16]);
        make.size.mas_equalTo([SFitUtil fitSize:280 height:280]);
        make.centerX.mas_equalTo(0);
    }];
    [self.btnFinish mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-IPHONE_X_BOTTOM_HEIGHT-[SFitUtil fit:15]);
        make.size.mas_equalTo([SFitUtil fitSize:345 height:54]);
        make.centerX.mas_equalTo(0);
        make.top.equalTo(self.svMain.mas_bottom).offset([SFitUtil fit:30]);
    }];
}


- (void)finishClickAction:(id)sender{
    YMCheckCameraStatusVC *vc = [[YMCheckCameraStatusVC alloc] init];
    vc.checkModel = self.checkModel;
    vc.hidesBottomBarWhenPushed = YES;
    [SJumpUtil pushVC:vc animated:YES];
}

#pragma mark -- setter and getter
- (UIScrollView *)svMain{
    if (_svMain == nil){
        _svMain = [[UIScrollView alloc] init];
        _svMain.showsVerticalScrollIndicator = YES;
        _svMain.showsHorizontalScrollIndicator = NO;
        _svMain.clipsToBounds = YES;
        _svMain.layer.cornerRadius = [SFitUtil fit:8];
    }
    return _svMain;
}
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.clipsToBounds = YES;
        _vBg.layer.cornerRadius = [SFitUtil fit:8];
    }
    return _vBg;
}
- (UILabel *)lblTips{
    if (_lblTips == nil){
        _lblTips = [SThemeUtil boldLabel:@"" color:STheme.H_D1 fontSize:16];
        _lblTips.numberOfLines = 0;
        
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        style.lineSpacing = [SFitUtil fit:8];
        NSAttributedString *attr = [[NSAttributedString alloc] initWithString:KLanguage(@"sampling_photo_hint") attributes:@{NSParagraphStyleAttributeName: style}];
        _lblTips.attributedText = attr;
        _lblTips.textAlignment = NSTextAlignmentCenter;
    }
    return _lblTips;
}
- (UIImageView *)imgvIcon{
    if (_imgvIcon == nil) {
        _imgvIcon = [[FLAnimatedImageView alloc] init];
        _imgvIcon.loopCountdown = 1;
        NSString *path = [[NSBundle mainBundle] pathForResource:@"check_insert_instrument" ofType:@"gif"];
        NSData *data = [NSData dataWithContentsOfFile:path];
        FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:data];
        _imgvIcon.animatedImage = animatedImage;
    }
    return _imgvIcon;
}
- (UIButton *)btnFinish{
    if (_btnFinish == nil){
        _btnFinish = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnFinish setTitle:KLanguage(@"inserted_card_txt") forState:UIControlStateNormal];
        [_btnFinish setTitleColor:STheme.D9 forState:UIControlStateNormal];
        _btnFinish.titleLabel.font = [SFitUtil fitBoldFont:16];
        [_btnFinish addTarget:self action:@selector(finishClickAction:) forControlEvents:UIControlEventTouchUpInside];
        _btnFinish.backgroundColor = STheme.D12;
        _btnFinish.layer.cornerRadius = [SFitUtil fit:10];
        _btnFinish.clipsToBounds = YES;
    }
    return _btnFinish;
}

@end
